home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / blt2.4 / tabset.tcl < prev    next >
Encoding:
Text File  |  2009-12-04  |  10.2 KB  |  326 lines

  1. #
  2. # tabset.tcl
  3. #
  4. # ----------------------------------------------------------------------
  5. # Bindings for the BLT tabset widget
  6. # ----------------------------------------------------------------------
  7. #   AUTHOR:  George Howlett
  8. #            Bell Labs Innovations for Lucent Technologies
  9. #            gah@bell-labs.com
  10. #            http://www.tcltk.com/blt
  11. # ----------------------------------------------------------------------
  12. # Copyright (c) 1998  Lucent Technologies, Inc.
  13. # ======================================================================
  14. #
  15. # Permission to use, copy, modify, and distribute this software and its
  16. # documentation for any purpose and without fee is hereby granted,
  17. # provided that the above copyright notice appear in all copies and that
  18. # both that the copyright notice and warranty disclaimer appear in
  19. # supporting documentation, and that the names of Lucent Technologies
  20. # any of their entities not be used in advertising or publicity
  21. # pertaining to distribution of the software without specific, written
  22. # prior permission.
  23. #
  24. # Lucent Technologies disclaims all warranties with regard to this
  25. # software, including all implied warranties of merchantability and
  26. # fitness.  In no event shall Lucent be liable for any special, indirect
  27. # or consequential damages or any damages whatsoever resulting from loss
  28. # of use, data or profits, whether in an action of contract, negligence
  29. # or other tortuous action, arising out of or in connection with the use
  30. # or performance of this software.
  31. #
  32. # ======================================================================
  33.  
  34. #
  35. # Indicates whether to activate (highlight) tabs when the mouse passes
  36. # over them.  This is turned off during scan operations.
  37. #
  38. set bltTabset(activate) yes
  39.  
  40. # ----------------------------------------------------------------------
  41. # ButtonPress assignments
  42. #
  43. #   <ButtonPress-2>    Starts scan mechanism (pushes the tabs)
  44. #   <B2-Motion>        Adjust scan
  45. #   <ButtonRelease-2>    Stops scan
  46. #
  47. # ----------------------------------------------------------------------
  48. bind Tabset <B2-Motion> {
  49.     %W scan dragto %x %y
  50. }
  51.  
  52. bind Tabset <ButtonPress-2> {
  53.     set bltTabset(cursor) [%W cget -cursor]
  54.     set bltTabset(activate) no
  55.     %W configure -cursor hand1
  56.     %W scan mark %x %y
  57. }
  58.  
  59. bind Tabset <ButtonRelease-2> {
  60.     %W configure -cursor $bltTabset(cursor)
  61.     set bltTabset(activate) yes
  62.     %W activate @%x,%y
  63. }
  64.  
  65. # ----------------------------------------------------------------------
  66. # KeyPress assignments
  67. #
  68. #   <KeyPress-Up>    Moves focus to the tab immediately above the 
  69. #            current.
  70. #   <KeyPress-Down>    Moves focus to the tab immediately below the 
  71. #            current.
  72. #   <KeyPress-Left>    Moves focus to the tab immediately left of the 
  73. #            currently focused tab.
  74. #   <KeyPress-Right>    Moves focus to the tab immediately right of the 
  75. #            currently focused tab.
  76. #   <KeyPress-space>    Invokes the commands associated with the current
  77. #            tab.
  78. #   <KeyPress-Return>    Same as above.
  79. #   <KeyPress>        Go to next tab starting with the ASCII character.
  80. #
  81. # ----------------------------------------------------------------------
  82. bind Tabset <KeyPress-Up> { blt::SelectTab %W "up" }
  83. bind Tabset <KeyPress-Down> { blt::SelectTab %W "down" }
  84. bind Tabset <KeyPress-Right> { blt::SelectTab %W "right" }
  85. bind Tabset <KeyPress-Left> { blt::SelectTab %W "left" }
  86. bind Tabset <KeyPress-space> { %W invoke focus }
  87. bind Tabset <KeyPress-Return> { %W invoke focus }
  88.  
  89. bind Tabset <KeyPress> {
  90.     if { [string match {[A-Za-z0-9]*} "%A"] } {
  91.     blt::FindMatchingTab %W %A
  92.     }
  93. }
  94.  
  95. # ----------------------------------------------------------------------
  96. #
  97. # FirstMatchingTab --
  98. #
  99. #    Find the first tab (from the tab that currently has focus) 
  100. #    starting with the same first letter as the tab.  It searches
  101. #    in order of the tab positions and wraps around. If no tab
  102. #    matches, it stops back at the current tab.
  103. #
  104. # Arguments:    
  105. #    widget        Tabset widget.
  106. #    key        ASCII character of key pressed
  107. #
  108. # ----------------------------------------------------------------------
  109. proc blt::FindMatchingTab { widget key } {
  110.     set key [string tolower $key]
  111.     set itab [$widget index focus]
  112.     set numTabs [$widget size]
  113.     for { set i 0 } { $i < $numTabs } { incr i } {
  114.     if { [incr itab] >= $numTabs } {
  115.         set itab 0
  116.     }
  117.     set name [$widget get $itab]
  118.     set label [string tolower [$widget tab cget $name -text]]
  119.     if { [string index $label 0] == $key } {
  120.         break
  121.     }
  122.     }
  123.     $widget focus $itab
  124.     $widget see focus
  125. }
  126.  
  127. # ----------------------------------------------------------------------
  128. #
  129. # SelectTab --
  130. #
  131. #    Invokes the command for the tab.  If the widget associated tab 
  132. #    is currently torn off, the tearoff is raised.
  133. #
  134. # Arguments:    
  135. #    widget        Tabset widget.
  136. #    x y        Unused.
  137. #
  138. # ----------------------------------------------------------------------
  139. proc blt::SelectTab { widget tab } {
  140.     set index [$widget index $tab]
  141.     if { $index != "" } {
  142.     $widget select $index
  143.     $widget focus $index
  144.     $widget see $index
  145.     set w [$widget tab tearoff $index]
  146.     if { ($w != "") && ($w != "$widget") } {
  147.         raise [winfo toplevel $w]
  148.     }
  149.     $widget invoke $index
  150.     }
  151. }
  152.  
  153. # ----------------------------------------------------------------------
  154. #
  155. # DestroyTearoff --
  156. #
  157. #    Destroys the toplevel window and the container tearoff 
  158. #    window holding the embedded widget.  The widget is placed
  159. #    back inside the tab.
  160. #
  161. # Arguments:    
  162. #    widget        Tabset widget.
  163. #    tab        Tab selected.
  164. #
  165. # ----------------------------------------------------------------------
  166. proc blt::DestroyTearoff { widget tab } {
  167.     regsub -all {\.} [$widget get $tab] {_} name
  168.     set top "$widget.toplevel-$name"
  169.     if { [winfo exists $top] } {
  170.     wm withdraw $top
  171.     update
  172.     $widget tab tearoff $tab $widget
  173.     destroy $top
  174.     }
  175. }
  176.  
  177. # ----------------------------------------------------------------------
  178. #
  179. # CreateTearoff --
  180. #
  181. #    Creates a new toplevel window and moves the embedded widget
  182. #    into it.  The toplevel is placed just below the tab.  The
  183. #    DELETE WINDOW property is set so that if the toplevel window 
  184. #    is requested to be deleted by the window manager, the embedded
  185. #    widget is placed back inside of the tab.  Note also that 
  186. #    if the tabset container is ever destroyed, the toplevel is
  187. #    also destroyed.  
  188. #
  189. # Arguments:    
  190. #    widget        Tabset widget.
  191. #    tab        Tab selected.
  192. #    x y        The coordinates of the mouse pointer.
  193. #
  194. # ----------------------------------------------------------------------
  195. proc blt::CreateTearoff { widget tab rootX rootY } {
  196.  
  197.     # ------------------------------------------------------------------
  198.     # When reparenting the window contained in the tab, check if the
  199.     # window or any window in its hierarchy currently has focus.
  200.     # Since we're reparenting windows behind its back, Tk can
  201.     # mistakenly activate the keyboard focus when the mouse enters the
  202.     # old toplevel.  The simplest way to deal with this problem is to
  203.     # take the focus off the window and set it to the tabset widget
  204.     # itself.
  205.     # ------------------------------------------------------------------
  206.  
  207.     set focus [focus]
  208.     set name [$widget get $tab]
  209.     set window [$widget tab cget $name -window]
  210.     if { ($focus == $window) || ([string match  $window.* $focus]) } {
  211.     focus -force $widget
  212.     }
  213.     regsub -all {\.} [$widget get $tab] {_} name
  214.     set top "$widget.toplevel-$name"
  215.     toplevel $top
  216.     $widget tab tearoff $tab $top.container
  217.     table $top $top.container -fill both
  218.  
  219.     incr rootX 10 ; incr rootY 10
  220.     wm geometry $top +$rootX+$rootY
  221.     set name [$widget get $tab]
  222.  
  223.     set parent [winfo toplevel $widget]
  224.     wm title $top "[wm title $parent]: [$widget tab cget $name -text]"
  225.     wm transient $top $parent
  226.  
  227.     #blt::winop changes $top
  228.  
  229.     # 
  230.     # If the user tries to delete the toplevel, put the window back
  231.     # into the tab folder.  
  232.     #
  233.     wm protocol $top WM_DELETE_WINDOW [list blt::DestroyTearoff $widget $tab]
  234.     # 
  235.     # If the container is ever destroyed, automatically destroy the
  236.     # toplevel too.  
  237.     #
  238.     bind $top.container <Destroy> [list destroy $top]
  239. }
  240.  
  241. # ----------------------------------------------------------------------
  242. #
  243. # Tearoff --
  244. #
  245. #    Toggles the tab tearoff.  If the tab contains a embedded widget, 
  246. #    it is placed inside of a toplevel window.  If the widget has 
  247. #    already been torn off, the widget is replaced back in the tab.
  248. #
  249. # Arguments:    
  250. #    widget        tabset widget.
  251. #    x y        The coordinates of the mouse pointer.
  252. #
  253. # ----------------------------------------------------------------------
  254. proc blt::Tearoff { widget x y index } {
  255.     set tab [$widget index -index $index]
  256.     if { $tab == "" } {
  257.     return
  258.     }
  259.     $widget invoke $tab
  260.  
  261.     set container [$widget tab tearoff $index]
  262.     if { $container == "$widget" } {
  263.     blt::CreateTearoff $widget $tab $x $y
  264.     } elseif { $container != "" } {
  265.     blt::DestroyTearoff $widget $tab
  266.     }
  267. }
  268.  
  269. # ----------------------------------------------------------------------
  270. #
  271. # TabsetInit
  272. #
  273. #    Invoked from C whenever a new tabset widget is created.
  274. #    Sets up the default bindings for the all tab entries.  
  275. #    These bindings are local to the widget, so they can't be 
  276. #    set through the usual widget class bind tags mechanism.
  277. #
  278. #    <Enter>        Activates the tab.
  279. #    <Leave>        Deactivates all tabs.
  280. #    <ButtonPress-1>    Selects the tab and invokes its command.
  281. #    <Control-ButtonPress-1>    
  282. #            Toggles the tab tearoff.  If the tab contains
  283. #            a embedded widget, it is placed inside of a
  284. #            toplevel window.  If the widget has already
  285. #            been torn off, the widget is replaced back
  286. #            in the tab.
  287. #
  288. # Arguments:    
  289. #    widget        tabset widget
  290. #
  291. # ----------------------------------------------------------------------
  292. proc blt::TabsetInit { widget } {
  293.     $widget bind all <Enter> { 
  294.     if { $bltTabset(activate) } {
  295.         %W activate current
  296.         }
  297.     }
  298.     $widget bind all <Leave> { 
  299.         %W activate "" 
  300.     }
  301.     $widget bind all <ButtonPress-1> { 
  302.     blt::SelectTab %W "current"
  303.     }
  304.     $widget bind all <Control-ButtonPress-1> { 
  305.     if { [%W cget -tearoff] } {
  306.         blt::Tearoff %W %X %Y active
  307.     }
  308.     }
  309.     $widget configure -perforationcommand {
  310.     blt::Tearoff %W $bltTabset(x) $bltTabset(y) select
  311.     }
  312.     $widget bind Perforation <Enter> { 
  313.     %W perforation activate on
  314.     }
  315.     $widget bind Perforation <Leave> { 
  316.     %W perforation activate off
  317.     }
  318.     $widget bind Perforation <ButtonPress-1> { 
  319.     set bltTabset(x) %X
  320.     set bltTabset(y) %Y
  321.     %W perforation invoke
  322.     }
  323. }
  324.